package com.ruoyi.student.controller;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.student.domain.StudentCourse;
import com.ruoyi.student.service.IStudentCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生课Controller
 *
 * @author 刘红
 * @date 2023-11-29
 */
@Api(tags="学生课管理")
@RestController
@RequestMapping("/student/course")
public class StudentCourseController extends BaseController
{
    @Autowired
    private IStudentCourseService studentCourseService;

    /**
     * 查询学生课列表
     */
    @ApiOperation("查询学生课列表")
    @PreAuthorize("@ss.hasPermi('student:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentCourse studentCourse)
    {
        startPage();
        List<StudentCourse> list = studentCourseService.selectStudentCourseList(studentCourse);
        return getDataTable(list);
    }

    /**
     * 导出学生课列表
     */
    @ApiOperation("导出学生课列表")
    @PreAuthorize("@ss.hasPermi('student:course:export')")
    @Log(title = "学生课", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentCourse studentCourse)
    {
        List<StudentCourse> list = studentCourseService.selectStudentCourseList(studentCourse);
        ExcelUtil<StudentCourse> util = new ExcelUtil<StudentCourse>(StudentCourse.class);
        util.exportExcel(response, list, "学生课数据");
    }

    /**
     * 获取学生课详细信息
     */
    @ApiOperation("获取学生课详细信息")
    @PreAuthorize("@ss.hasPermi('student:course:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(studentCourseService.getById(id));
    }

    /**
     * 新增学生课
     */
    @ApiOperation("新增学生课")
    @PreAuthorize("@ss.hasPermi('student:course:add')")
    @Log(title = "学生课", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentCourse studentCourse)
    {
        return toAjax(studentCourseService.save(studentCourse));
    }

    /**
     * 修改学生课
     */
    @ApiOperation("修改学生课")
    @PreAuthorize("@ss.hasPermi('student:course:edit')")
    @Log(title = "学生课", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentCourse studentCourse)
    {
        return toAjax(studentCourseService.updateById(studentCourse));
    }

    /**
     * 删除学生课
     */
    @ApiOperation("删除学生课")
    @PreAuthorize("@ss.hasPermi('student:course:remove')")
    @Log(title = "学生课", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(studentCourseService.removeByIds(Arrays.asList(ids)));
    }
}
